<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="css/style.css" />
<link type="text/css" rel="stylesheet" href="css/layout.css" />
<title>Admin control panel !</title>
</head>

<body>
<?php include("menu.php"); 
include("session.php");
include("../include/config.php");
?>


<?php
	if (isset($_REQUEST["id"]))
	{
		$ID = $_REQUEST["id"];
		$sql3="SELECT * FROM product WHERE  id=$ID";
		$rs=mysql_query($sql3);
		if($rs) {
			$rw = mysql_fetch_array($rs);
		}
		else
			die("Lỗi: Mã sản phẩm không tồn tại!");
	}
?>


<div id="head-noidung">
	<div id="head-main">
	<form name="product" method="get"  enctype="multipart/form-data">
	<input type="text" name="id" hidden="yes" value=<?php echo $rw["id"] ?> />
	<table class="classtable">
	<tbody">
	<tr>
	<td>Tên sản phẩm:</td>
	<td><input name="name" type="text" size="35" style="float:left;" value="<?php echo $rw["name"]; ?>" ></td>
	</tr>
	
	<tr>
	<td>Mã sản phẩm</td>
	<td><input name="code" type="text" size="5" style="float:left;" value="<?php echo $rw["code"] ?>"></td>
	</tr>
	
	<tr>
	<td>Giá</td>
	<td><input name="price" type="text" size="25" style="float:left;" value="<?php echo $rw["price"] ?>"></td>
	</tr>
	
	<tr>
	<td>Giá khuyến mãi</td>
	<td><input name="pricesale" type="text" size="25" style="float:left;" value="<?php echo $rw["pricesale"] ?>"></td>
	</tr>

	
	<tr>
	<td>Loại sản phẩm</td>
	<td>		
	<select name="subcategory_id">
<?php 
	$sql2="SELECT * FROM subcategory ORDER BY stt";
	$rs2=mysql_query($sql2);
	if($rs2) {
		while($rw2=mysql_fetch_array($rs2)) {
			$selected = "";
			if ($rw2["id"] == $rw["subcategory"])
				$selected = "selected='selected'";
			echo "<option value=$rw2[id] " . $selected . ">$rw2[name]</option>";
		}
		
	}
?>
	</select>
	
	</tr>
	<tr>
	<td>Mô tả</td>
	<td><textarea name="description" cols="70" rows="5" value=<?php echo $rw["description"] ?>></textarea></td>
	</tr>		
	
	   <tr>
      <td>Ảnh sản phẩm</td>
      <td>
	  <?php ?>
	  <img src="../images/product/<?php echo $rw["image"]?>" name="images" />
       </td>
	   </tr>
	
	<tr>
	<td></td>
	<td><input type="submit" name="update" value="Sửa" /></td>
	</tr>
	<?php
	if (isset($_REQUEST["success"]))
		echo ("<center><font color='red'>Sửa thành công</font></center>");
	?>
	</tbody>
	</table>
	</form>


<?php 
	if(isset($_REQUEST["update"])) {
	$id = $_REQUEST["id"];
	$name=$_REQUEST["name"];
	$code=$_REQUEST["code"];
	$price=$_REQUEST["price"];
	$pricesale=$_REQUEST["pricesale"];
	$subcategory=$_REQUEST["subcategory_id"];
	$description=$_REQUEST["description"];
	$sql="UPDATE product SET name='".$name.
	"', code='".$code.
	"', price='".$price.
	"', pricesale='".$pricesale.
	"', subcategory='".$subcategory.
	"', description='".$description.
	"', status=1 WHERE id='$id'";
	//echo "[$sql]";
	header("Location: product_edit.php?id=$id&success=1");
	$rs=mysql_query($sql);
	if($rs)
		{ echo ("Sửa thành công");
		}
	else { echo ("Truy vấn sai");
		}	
	}
?>	
	</div>	
</div>

<?php include("images/cherry/footer.php"); ?>

</body>
</html>
